#include "Tile.h"

#include "Camera.h"

#include <Windows.h>

// Constructor
Tile::Tile(void)
{
	
}

// Destructor
Tile::~Tile(void)
{
}

// SetSourceRect
//	- Sets the rectangle in the source image that the tile
//	  renders from.
void Tile::SetSourceRect(RECT rect)
{
	this->srcRect = rect;
}

// Render
//	- Renders the tile.
void Tile::Render(void) const
{
	Camera* camera = Camera::GetInstance();

	RECT cameraBounds;
	cameraBounds.left = (long)camera->OffsetX();
	cameraBounds.top = (long)camera->OffsetY();
	cameraBounds.right = cameraBounds.left + camera->ScreenWidth();
	cameraBounds.bottom = cameraBounds.top + camera->ScreenHeight();

	RECT rect;
	if(IntersectRect(&rect, &cameraBounds, &hitBox))
	{
		CSGD_TextureManager::GetInstance()->Draw(imageID, (int)(positionX - camera->OffsetX()),
			(int)(positionY - camera->OffsetY()), 1.0f, 1.0f, &GetSourceRect());
	}
}
